-- damage
-- create by zhuangsl
-- 道具：  按玩家基础属性造成伤害

return {
    apply = function(source, target, classId, value)
        -- 传入攻击者信息
        local assailantInfo = {};
        local pos = source["pos"];
        if pos then
            assailantInfo = {
                ["property_id"] = classId,
                ["pos"]         = pos,
            };
        else
            assailantInfo = {
                ["property_id"] = classId,
            };
        end

        local damageInfo = value;
        local attrib = damageInfo[1];
        local damage = math.modf(InterfaceM.calcBaseAttrib(source, attrib) * damageInfo[2] / 1000);

        -- 保底1点
        damage = math.max(1, damage);

        -- 计算最终伤害
        damage = PropertyM.calcFinalDamage(source, target, classId, damage);

        if ItemM.query(classId, "apply") == "damage_and_drop" then
            -- 会掉落道具
            CombatM.doDamage(source, target, damage, 0, true, { assailantInfo = assailantInfo, });
        else
            CombatM.doDamage(source, target, damage, 0, false, { assailantInfo = assailantInfo, });
        end

        -- 抛出使用道具攻击事件
        EventMgr.fire(event.PROPERTY_ATTACK, { ["classId"] = classId, ["target"] = target, ["source"] = source});
    end,
};
